package com.right.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**********************************************
 * @author pillar
 * @date 2018/6/13
 * 异常处理
 **********************************************/
@Slf4j
public class ExceptionHandler extends SimpleChannelInboundHandler {



    public ExceptionHandler() {

    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        log.error("异常捕获={}",cause.getMessage());
        Channel channel = ctx.channel();
        if(channel.isActive()) {
            ctx.close();
        }

    }
}
